package Demo1;

//用栈实现队列

import java.util.Stack;

/**
 * void push(int x) 将元素 x 推到队列的末尾
 * int pop() 从队列的开头移除并返回元素
 * int peek() 返回队列开头的元素
 * boolean empty() 如果队列为空，返回 true ；否则，返回 false
 */
class MyQueue {
    Stack<Integer> queue1;
    Stack<Integer> queue2;
    public MyQueue() {
        queue1 = new Stack<>();
        queue2 = new Stack<>();
    }

    //栈 先进后出 --- 队列 先进先出
    public void push(int x) {
        if (queue1.isEmpty()) {
            queue1.push(x);
        } else {
            while (!queue1.isEmpty()) {
                queue2.push(queue1.pop());
            }
            queue1.push(x);
            while(!queue2.isEmpty()) {
                queue1.push(queue2.pop());
            }
        }
    }

    public int pop() {
        return queue1.pop();
    }

    public int peek() {
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}

public class t6 {
    public static void main(String[] args) {


    }
}
